package com.dankegongyu.lib.common.util;

import org.joda.time.DateTime;

/**
 * 日期等
 *
 * @author wpq
 * @version 1.0
 */
public class DKDateUtil {

    public static final String DETAIL_TIME = "yyyy-MM-dd HH:mm";
    public static final String SHORT_TIME = "yyyy-MM-dd";
    public static final String SHORT_TIME_POINT = "yyyy.MM.dd";
    public static final String MONTH_DAY = "MM月dd日";
    public static final String MONTH_DAY_HOUR = "MM月dd日 HH:mm";

    private DKDateUtil() {
        throw new AssertionError("cannot be instantiated");
    }

    public static String formatDate(String date, String format) {
        return new DateTime(date).toString(format);
    }

    public static boolean equals(long date1, long date2, String format) {
        String s1 = new DateTime(date1).toString(format);
        String s2 = new DateTime(date2).toString(format);
        return s1 != null && s2 != null && s1.equals(s2);
    }

    public static boolean equals(String date1, String date2, String format) {
        String s1 = new DateTime(date1).toString(format);
        String s2 = new DateTime(date2).toString(format);
        return s1 != null && s2 != null && s1.equals(s2);
    }

    /**
     * 两个时间是否为一年中同一天
     */
    public static boolean isTheSameDayOfYear(long firstTime, long secondTime) {
        int firstDay = new DateTime(firstTime).getDayOfYear();
        int secondDay = new DateTime(secondTime).getDayOfYear();
        return firstDay == secondDay;
    }
}
